home *** CD-ROM | disk | FTP | other *** search
- /*
- This is a simple pop3 client.
- It connects a pop3 server and wait for commands.
- Be sure you know what you are doing, before connect
- to your popmail server and waste your mail.
- Usage: pop3 [HOST] [AUTO/S]
-
- HOST the hostname with the pop3 service to connect
- AUTO connect the pop3 service with login and password
- as defined later.
- */
-
- l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
- if AddLibrary("rexxsupport.library","rxsocket.library")~=0 then exit
-
- prg="pop3"
-
- if ~RMH_ReadArgs("HOST,AUTO/S") then do
- call PrintFault(IoErr(),prg)
- exit
- end
-
- if parm.1.flag then do
- /* PUT HERE YOUR DEFAULT HOST, LOGIN and PASS TO BE USED WITH AUTO OPTION */
- host="YOR DEF POP3 HOST"
- userName="YOR DEF LOGIN NAME"
- passWord="YOUR DEF LOGIN PASS"
- end
- else do
- if ~parm.0.flag then do
- call PrintFault(116,"pop3")
- exit
- end
- host=parm.0.value
- end
- /******************************************************/
- sock = OpenConnection("tcp","pop3",host)
- if sock<0 then do
- select
- when sock==-3 then
- say "pop3: service pop3 not found"
- when sock==-2 then
- say "pop3: host <" || host || "> not found (" || HostErrorno() || ")"
- when sock==-1 then
- say "pop3: unable to connect pop3 service at <" || host || "> (" || errno() || ")"
- end
- exit
- end
- /******************************************************/
- CRLF = "D"x || "A"x
- ENDMULTI = "."
- call rec("SINGLE")
- if parm.1.flag then do
- call sen("USER" userName)
- call rec("SINGLE")
- call sen("PASS" password)
- call rec("SINGLE")
- end
- call init
- /******************************************************/
- do forever
- parse pull com arg1 arg2 .
- com = upper(com)
- if symbol(com)~="LIT" then err=2
- else do
- err=0
- if value(pop3.com.type)~="POP3."COM".TYPE" then do
- if (pop3.com.args>0 & arg1=="") | (pop3.com.args>1 & arg2=="") then
- err=1
- end
- else err=2
- end
- if err~=0 then
- select
- when err=1 then say com "need" pop3.com.args "arguments"
- when err=2 then say "unknown command" com
- end
- else do
- if com=="QUITND" then exit
- if arg2="" then call sen(com arg1)
- else call sen(com arg1 arg2)
- call rec(pop3.com.type)
- say
- if pop3.com.finish==1 then exit
- end
- end
- exit
- /******************************************************/
- init:
- pop3.USER.type="SINGLE";pop3.USER.args=1
- pop3.PASS.type="SINGLE";pop3.PASS.args=1
- pop3.STAT.type="SINGLE";pop3.STAT.args=0
- pop3.LIST.type="MULTI"; pop3.LIST.args=0
- pop3.RETR.type="MULTI"; pop3.RETR.args=1
- pop3.NOOP.type="SINGLE";pop3.NOOP.args=0
- pop3.QUIT.type="SINGLE";pop3.QUIT.args=0;pop3.QUIT.finish=1
- pop3.QUITND.type="SINGLE";pop3.QUITND.args=0;pop3.QUITND.finish=1
- pop3.TOP.type= "MULTI"; pop3.TOP.args=2
- pop3.UIDL.type="SINGLE";pop3.UIDL.args=1
- pop3.DELE.type= "SINGLE";pop3.DELE.args=1
- pop3.RSET.type="SINGLE";pop3.RSET.args=0
- return
- /******************************************************/
- sen:
- parse arg string
- string = string || CRLF
- res = send(sock,string)
- if res~=length(string) then do
- say "pop3: send error (" || errno() || ")"
- exit
- end
- return
- /******************************************************/
- rec:
- parse arg comType
- first=1
- do forever
- len = recvline(sock,"BUF",256)
- if len<0 then do
- say "pop3: recv error (" || errno() || ")"
- exit
- end
- parse var buf buf "D"x
- if first then do
- if left(buf,1)=="-" then do
- parse var buf "-ERR " text
- say " Error from server" text
- return
- end
- parse var buf buf "+OK " buf
- first=0
- end
- if comType=="MULTI" then
- if buf=ENDMULTI then return
- say buf
- if comType=="SINGLE" then return
- end
- /******************************************************/
-